package com.huadao.pda.project.projectDetail;

import com.huadao.pda.data.bean.DeviceInfo;
import com.huadao.pda.data.http.RockBaseObserver;
import com.huadao.pda.modle.DeviceInfoModle;
import com.huadao.pda.modle.ProjectModel;

import io.reactivex.Observable;

public class ProjectDetailPresenter extends ProjectDetailContract.IProjectDetailPresenter {

    private DeviceInfoModle deviceInfoModle;
    public ProjectDetailPresenter(ProjectDetailContract.IProjectDetailView baseView) {
        attachView(baseView);
        deviceInfoModle=new DeviceInfoModle(baseView.getContext());
    }

    @Override
    void getDeviceByDeviceId(String id) {
        Observable<DeviceInfo> observable=deviceInfoModle.getDeviceById(id);
        deviceInfoModle.toSubscribe(observable, new RockBaseObserver<DeviceInfo>(this) {
            @Override
            protected void onBaseNext(DeviceInfo data) {
                baseView.onGetDevice(data);
            }
        });
    }

    @Override
    void scanLogin(String projectId, String devId, String loginCode) {
        Observable observable=deviceInfoModle.swapLogin(projectId, devId, loginCode);
        deviceInfoModle.toSubscribe(observable, new RockBaseObserver<Boolean>(this,"扫码成功，正在登陆") {

            @Override
            protected void onBaseNext(Boolean data) {
                baseView.onScanLogin();
            }
        });
    }
}
